import { Request, Response } from 'express';
import { wechatService } from '../services/wechatService';

export const getWechatJSSDKConfig = async (req: Request, res: Response) => {
  try {
    const { url } = req.query;
    
    if (!url || typeof url !== 'string') {
      return res.status(400).json({
        success: false,
        message: '缺少url参数',
      });
    }

    const config = await wechatService.getJSSDKConfig(url);
    
    res.json({
      success: true,
      data: config,
    });
  } catch (error) {
    console.error('获取微信JS-SDK配置失败:', error);
    res.status(500).json({
      success: false,
      message: '获取微信JS-SDK配置失败',
    });
  }
};
